package czopyk.model.persistence.actions;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.google.common.collect.BiMap;

import pl.czopyk.view.QuickDrawer;
import czopyk.model.persistence.ValueExtractor;

public class VisualizeDistributionAction extends CommonAction implements Action {

	private final Long id;
	private Map<Long, List<Double>> distributions;
	
	private String label, chart;
	private boolean pdf;

	public VisualizeDistributionAction(String var, String label, String chart,
			boolean pdf, BiMap<Long, String> idToVar, Map<Long, List<Double>> distributions, 
			ValueExtractor ve) {
		super(null, ve);
		this.label = label;
		this.chart = chart;
		this.pdf = pdf;
		this.distributions = distributions;
		
		// id zmiennej 'var'
		id = idToVar.inverse().get(var);
		if (id == null) {
			throw new IllegalStateException("No id found for variable \"" + var
					+ "\". Does condition have proper var?");
		}
		// rozklady
		distributions.put(id, new LinkedList<Double>());
	}

	public void perform() {
		String l = ve.getValue(label);
		String c = ve.getValue(chart);

		List<Double> list = distributions.get(id);
		// list = Utils.removeExtreme(list, 0.025);
		QuickDrawer.visualize(list, l.toString(), c.toString(), pdf);
	}
	
}

